﻿using System;
using RpcClient.Helper;
using RpcClient.Interface;
using RpcClient.Tran.Saga;

namespace RpcClient.Collect
{
    [Attr.ClassLifetimeAttr(Attr.ClassLifetimeType.单例)]
    internal class RpcSagaTranCollect : IRpcSagaTranService
    {
        public void RegTran<T, Extend>(string name, Action<T, Extend> rollback) where T : class
        {
            RpcTranCollect.RegTran(name, new BasicTranTemplate<T, Extend>(name, rollback));
        }

        public void RegTran<T, Extend>(Action<T, Extend> rollback) where T : class
        {
            string name = TranHelper.GetTranName(typeof(T));
            this.RegTran(name, rollback);
        }

        public void RegTran(string name, Action<string> rollback)
        {
            RpcTranCollect.RegTran(name, new NoParamTranTemplate(name, rollback));
        }

        public void RegTran<Extend>(string name, Action<Extend> rollback)
        {
            RpcTranCollect.RegTran(name, new NoParamTranTemplate<Extend>(name, rollback));
        }
        public void RegTran<T>(Action<T, string> rollback) where T : class
        {
            string name = TranHelper.GetTranName(typeof(T));
            this.RegTran(name, rollback);
        }
        public void RegTran<T>(string name, Action<T, string> rollback) where T : class
        {
            RpcTranCollect.RegTran(name, new TranTemplate<T>(name, rollback));
        }
    }
}
